﻿using System;
using System.Collections.Generic;
using System.Web;
using StampController.BL;
using StampController.BL.Models;
using StampController.Core;

namespace StampController
{
    public class Global : HttpApplication
    {

        private void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            Common.StampDic = new Dictionary<int, string>();
            Common.StampTypeDic = new Dictionary<int, string>();
            Common.RequiredTypeDic = new Dictionary<int, string>();
            var im = new CommonImpl();
            foreach (StampModel stampModel in im.GetStampList())
            {
                Common.StampDic.Add(stampModel.StampID, stampModel.Name);
            }
            foreach (StampTypeModel stampTypeModel in im.GetStampTypeList())
            {
                Common.StampTypeDic.Add(stampTypeModel.STID, stampTypeModel.Name);
            }
            foreach (RequiredTypeModel requiredTypeModel in im.GetRequiredTypeList())
            {
                Common.RequiredTypeDic.Add(requiredTypeModel.RequiredTypeID, requiredTypeModel.Name);
            }

            UrlRouting.Initialize();

        }

        private void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown
        }

        private void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs
        }

        private void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started
            //var user = SessionUtils.Get<UsersModel>("USER");

            //if (logger.IsDebugEnabled)
            //{
            //    logger.Debug(user.UserID + " logged in on " + Dns.GetHostName());    // + "(IP: " + Request.UserHostAddress + ")");
            //}
        }

        private void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.
            //var user = SessionUtils.Get<UsersModel>("USER");

            //if (logger.IsDebugEnabled)
            //{
            //    logger.Debug(user.UserID + " logged off on " + Dns.GetHostName());    // + "(IP: " + Request.UserHostAddress + ")");
            //}
        }
    }
}